﻿/*
 * Twipler - Twitter Web Client with features.
 *  
 *  Copyright (C) 2009, 2010. Ian Quigley
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details. 
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;


namespace Twipler.App.Machine.Instructions
{
    [InstructionAttibute("Declare a variable")]
    public class Declare : Instruction
    {
        private Variable _variable;

        public Declare(Variable variable)
        {
            _variable = variable;
        }

        public Declare(string type, string name)
        {
            _variable = new Variable(type, name);
        }

    	public override void Exec(Environment env)
        {
            if (env.Variables_Contains(_variable.Name))
                return;

            env.Variables_Add(_variable.Name, _variable.Value);            
        }

		public override string ToString()
		{
			return string.Format("declare {0}, {1}", _variable.Type.ToString().Replace("System.", ""), _variable.Name);
		}
    }
}